package com.xh.bussiness.textbook.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xh.bussiness.textbook.bean.request.TextbookModuleDetailRequest;
import com.xh.bussiness.textbook.dao.TextbookModuleDetailMapper;
import com.xh.bussiness.textbook.model.TextbookModuleDetail;
import com.xh.bussiness.textbook.service.ITextbookModuleDetailService;
import com.xh.core.bean.XhPage;
import com.xh.core.service.impl.BaseServiceImpl;
import com.xh.core.util.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 讲义模块内容表 服务实现类
 * </p>
 *
 * @author JQM
 * @since 2019-09-26
 */
@Service
public class TextbookModuleDetailServiceImpl extends BaseServiceImpl<TextbookModuleDetailMapper, TextbookModuleDetail> implements ITextbookModuleDetailService {
    @Override
    public XhPage queryTextbookModuleDetailPage(XhPage page, TextbookModuleDetailRequest bean) {
        QueryWrapper qw=new QueryWrapper<TextbookModuleDetail>();
        //拼装条件
        qw=prepareParams(bean, qw);

        return (XhPage) this.dao.selectPage(page,qw);
    }

    @Override
    public List queryTextbookModuleDetail(TextbookModuleDetailRequest bean) {
        QueryWrapper qw=new QueryWrapper<TextbookModuleDetail>();
        //拼装条件
        qw=prepareParams(bean, qw);

        return this.dao.selectList(qw);
    }

    @Override
    public void deleteByTextbookId(String textbookId) {
        this.dao.deleteByTextbookId(textbookId);
    }

    @Override
    public List<TextbookModuleDetail> queryTextbookModuleDetailListByParentId(String textbookId, String textbookModuleId) {
        QueryWrapper<TextbookModuleDetail> qw=new QueryWrapper<>();
        qw.eq("textbook_id",textbookId);
        if(!StringUtils.isEmpty(textbookModuleId)){
            qw.eq("textbook_module_id",textbookModuleId);
        }
        qw.orderByAsc("order_no");
        List<TextbookModuleDetail> details= this.selectList(qw, TextbookModuleDetail.class);
        return details;
    }


    /**
     * 准备条件
     * @param bean
     * @param qw
     */
    private QueryWrapper prepareParams(TextbookModuleDetailRequest bean, QueryWrapper qw) {
        if(bean.getIds()!=null&&bean.getIds().length>0){
            qw.in("id",bean.getIds());
        }
        return qw;
    }
}
